<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/list.css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <!-- logo -->
        <img src="./images/logo_003.jpg" alt="">
        <div class="content">
            <span>我的博客系统</span>
            <div class="opts">
                <a href="./blog_list.html">主页</a>
                <a href="./blog_eidt.html">写博客</a>
                <a href="logout">注销</a>
            </div>

        </div>
    </div>
    <!-- 正文部分 -->
    <div class="container">
        <!-- 左边区域 -->
        <div class="container-left">
            <div class="card">
                <img src="./images/nz1.jpeg" alt="">
                <h3></h3>
                <a href="#">Github</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右边区域 -->
        <div class="container-right">
            <!-- 博客正文 -->
            <!-- <div class="blog-content">
                <div class="blog-title">
                    这是我的第一篇博客
                </div>
                <div class="blog-datetime">
                    2023-03-18 10:50:06
                </div>
                <div class="content">
                    <p>这是我的第一篇博客内容Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui temporibus a incidunt
                        totam, tempora iste facere iusto aliquid odit voluptatum veniam optio dolorum, harum fugit
                        praesentium quo esse exercitationem delectus?</p>
                    <p>这是我的第一篇博客内容Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui temporibus a incidunt
                        totam, tempora iste facere iusto aliquid odit voluptatum veniam optio dolorum, harum fugit
                        praesentium quo esse exercitationem delectus?</p>
                </div>
                <div class="aEl">
                    <a href="./blog_details.html">查看全文 &gt;&gt; </a>
                </div>
                <hr>
            </div> -->
        </div>
    </div>
    <script src="js/app.js"></script>
    <script>
        getLoginStatus();
        function getBlogs(){
            $.ajax({
                type: 'get',
                url: 'blog',
                success: function(body){
                    let containerDiv = document.querySelector('.container-right');
                    for (let i = 0; i < body.length; i++){
                        let blog = body[i];

                        // 构建整个博客
                        let blogDiv = document.createElement('div');
                        blogDiv.className = 'blog-content';

                        // 构建标题
                        let titleDiv = document.createElement('div');
                        titleDiv.className = 'blog-title';
                        titleDiv.innerHTML = blog.title;
                        // 构建发布时间
                        let dateDiv = document.createElement('div');
                        dateDiv.className = 'blog-datetime';
                        dateDiv.innerHTML = blog.postTime;
                        // 构建博客的摘要
                        let descDiv = document.createElement('div');
                        descDiv.className = 'content';
                        descDiv.innerHTML = blog.content;
                        // 构造查看全文按钮
                        let aEl = document.createElement('div');
                        aEl.className = 'aEl';

                        let a = document.createElement('a');
                        a.innerHTML = '查看全文 &gt;&gt;';
                        // 点击不同博客要跳转到不同的博客详情页
                        a.href = 'blog_details.html?blogId=' + blog.blogId;
                        aEl.appendChild(a);
                        blogDiv.appendChild(titleDiv);
                        blogDiv.appendChild(dateDiv);
                        blogDiv.appendChild(descDiv);
                        blogDiv.appendChild(aEl);

                        containerDiv.appendChild(blogDiv);
                    }
                }
            });
        }

        getBlogs();

        function getUserInfo(){
            $.ajax({
                type: 'get',
                url: 'userInfo',
                success: function(user){
                    let h3 = document.querySelector('.card h3');
                    h3.innerHTML = user.username;
                }
            });
        }

        getUserInfo();
    </script>
</body>

</html>